import { Router, Route, Switch } from "dva/router";
import dynamic from "dva/dynamic";
import App from "./page/App";
import Home from "./page/home";

function RouterConfig({ history, app }) {
  const routes = [
    {
      path: "/home",
      component: () => Home,
      // models: () => [import("./models/home/index")]
    },
    {
      path: "/user",
      component: () => import("./page/user/index.tsx"),
      // models: () => [import("./models/home/index")]
    },
  ];
  return (
    <Router history={history}>
      <App>
        <Switch>
          {/* 这里路由重定向 */}
          {/* <Route path="/" exact render={() => <Redirect to="/home" />} /> */}
          {routes.map(({ path, ...dynamics }, key) => (
            <Route
              key={key}
              exact
              path={path}
              component={dynamic({
                app,
                ...dynamics,
              })}
            ></Route>
          ))}
          {/* 404在此 */}
          {/* <Route component={NoMatch} /> */}
        </Switch>
      </App>
    </Router>
  );
}

export default RouterConfig;
